<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix='fmt' uri="http://java.sun.com/jsp/jstl/fmt" %> 
<%@ taglib prefix='c' uri="http://java.sun.com/jsp/jstl/core" %>  
<div class="clearfix">
<div>
<c:if test="${not empty appList}">                         
<table id="tdata1" cellspacing="0" cellpadding="0" border="0"
	width="100%">
	<thead>
		<tr>
			<th><fmt:message key="item" /></th>
			<th><fmt:message key="appDate" /></th>
			<th><fmt:message key="remark" /></th>
			<th><fmt:message key="status" /></th>
			<th>&nbsp;</th>
		</tr>
	</thead>
	<tbody>
		<c:forEach items="${appList }" var="app">

		<tr>
			<td><a href="javascript:void(0)" onClick="viewComments('${app.id}');">${ app.item }</a></td>
			<td>${ app.appDateAsStr }</td>
			<td>${ app.remark }</td>
			<td>${ app.status }
			<c:if test="${ not empty app.newCommentBy && USI.username != app.newCommentBy}">
			   <img src="/images/new_msg.jpg" alt="您有新的备注"/>
			</c:if> 
			</td>
			<td>
			<c:choose>
			<c:when test="${type  eq 'delete'}">
			<a class="ico_user_delete" title="<fmt:message key="deleteApp" />"
				href="javascript:void(0)" onClick="deleteApp('${app.id}');"></a>
			</c:when>
			<c:when test="${type eq 'assess' }">	
			<a class="ico_user_approve" title="<fmt:message key="approveApp" />"
				href="javascript:void(0)" onClick="approveApp('${app.id}');"></a><a class="ico_user_reject" title="<fmt:message key="rejectApp" />"
				href="javascript:void(0)" onClick="rejectApp('${app.id}');"></a>
			</c:when>
			<c:when test="${type eq 'cancelHis' }">	
                              <c:if test="${ app.status != 'Cancel' }">
			    <a class="ico_user_cancel" title="<fmt:message key="cancelHisApp" />"
				href="javascript:void(0)" onClick="cancelApp('${app.id}');"></a>
			</c:if> 
			</c:when>
			<c:when test="${type eq 'cancelMy' }">	
			<c:if test="${ app.status != 'Cancel' }">
			<a class="ico_user_cancel" title="<fmt:message key="cancelMyApp" />"
				href="javascript:void(0)" onClick="cancelOwnApp('${app.id}');"></a>
			</c:if> 
			</c:when>		
			</c:choose>
			
			</td>
		</tr>
		</c:forEach>
	</tbody>
</table>
</c:if>
<c:if test="${empty appList}"> 
 <fmt:message key="msg.NoAppFound" /> 
</c:if>
    </div>




        </div>
        


<script type="text/javascript" src="/js/jquery.dataTables.js"></script>
<script charset="utf-8" src="/js/jquery.lightbox-0.5.min.js"></script>

<script type="text/javascript">
		$(function(){
			var tdata1;
			
			// datatable
			tdata1 = $('#tdata1').dataTable({
				"sPaginationType": "full_numbers",
				"bFilter": true,
				"iDisplayLength": 5,
				"aaSorting": [[ 1, "desc" ]],
				//<c:if test="${currentLocaleLanguage eq 'zh'}">
				"oLanguage":{"sUrl": "/js/zh_CN.txt"},
				//</c:if>
				"aoColumnDefs": [ 
                                             { "bSortable": true, "aTargets": [ 0 ],  "sWidth": "190px" },
                                             { "bSortable": true, "aTargets": [ 1 ], "sClass": "center_text", "sWidth": "150px" },
                                            // { "bSortable": true, "aTargets": [ 2 ], "sClass": "center_text", "sWidth": "44px" },
                                             { "bSortable": true, "aTargets": [ 3 ],  "sWidth": "80px" },
                                             { "bSortable": false, "aTargets": [ 4 ],  "sWidth": "45px" }	
				]
			});
			
			// init
			//$('#tdata1_filter').hide();
			$('.cloas_lightbox').lightBox();
		});

		function viewComments(appId){
			var ret = window.showModalDialog('/process/viewComments.tt?appId='+appId,window,'dialogWidth:1000px;dialogHeight:700px');
			if(ret== 'SF'){
			  window.location.reload();
			}
		}
           
		function approveApp(appId){
		  processApp(appId,"/process/approveHisApp.tt"); 
		}
		function rejectApp(appId){ 
	             processApp(appId,"/process/rejectHisApp.tt");  
			   
		}
		function cancelApp(appId){
	                processApp(appId,"/process/cancelHisApproveApp.tt"); 
		}
		function cancelOwnApp(appId){
			 
	               processApp(appId,"/process/cancelMyApproveApp.tt"); 
		}
		
		function deleteApp(appId){
		    processApp(appId,"/process/deleteMyPendingApp.tt"); 
		}

		function processApp(appId,action){
			if(confirm('<fmt:message key="msg.confirmprocess"/>')){
			   var appForm = createAppForm(appId);
			   appForm.attr('action',action)
			   appForm.submit();  
			}
		}

		function createAppForm(appId){
                       var appForm =$("<form></form>");
                       appForm.appendTo("body");
                       appForm.attr('method','post')
                       var appidinput = $("<input type='hidden' name='appId' />")
                       appidinput.attr('value',appId)
                       appForm.append(appidinput);
                       return appForm;
                       
		}
</script>
